package barney.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import barney.excepcion.DAOExcepcion;
import barney.negocio.SeguridadProducto;

/**
 * Servlet implementation class RegistrarUsuario
 */
@WebServlet("/RegistrarProductoServlet")
public class RegistrarProductoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegistrarProductoServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String nom = request.getParameter("nombre");
		String det = request.getParameter("detalle");
		String mod = request.getParameter("modelo");
		String col = request.getParameter("color");
		String sto = request.getParameter("stock");
		String can = request.getParameter("cantidad");
		String pre = request.getParameter("precio");
		String mar = request.getParameter("marca");
		String pro = request.getParameter("proveedor");
		String ume = request.getParameter("unidad");
					
		System.out.println("PRODUCTO INGRESADO:");
		System.out.println(nom);
		System.out.println(det);
		System.out.println(mod);
		System.out.println(col);
		System.out.println(sto);
		System.out.println(can);
		System.out.println(pre);
		System.out.println(mar);
		System.out.println(pro);
		System.out.println(ume);
		
		//Llamamos a la clase NEGOCIO
		SeguridadProducto neg = new SeguridadProducto();
		
		try{
			neg.insertarProducto(nom, det, mod, col, sto, can, pre, mar, pro, ume);	
			RequestDispatcher rd = request.getRequestDispatcher("/producto_registrar.jsp");
			rd.forward(request, response);
		}catch(DAOExcepcion e){
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");	
			rd.forward(request, response);
		}
				
	}

}
